package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.FileUploadService;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.utils.DYLAssert;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@Tag(name = "文件上传")
@RequestMapping("/admin")
@CrossOrigin(allowCredentials = "true", originPatterns = "*", allowedHeaders = "*")
public class FileUploadController {
    @Autowired
    private FileUploadService fileUploadService;

    @Operation(summary = "头像上传")
    @PostMapping("/system/avatarUpload")
    public Result avatarUpload(@RequestParam("file") MultipartFile file){
        return Result.ok(fileUploadService.avatarUpload(file));
    }

    @Operation(summary = "商品分类文件导入")
    @PostMapping("/product/categoryFileUpload")
    public Result categoryFileUpload(MultipartFile file){
        DYLAssert.notNull(file,"上传失败，文件为空");
        fileUploadService.categoryFileUpload(file);
        return Result.ok();
    }

    @Operation(summary = "logo上传")
    @PostMapping("/product/logoUpload")
    public Result logoUpload(@RequestParam("file") MultipartFile file){
        return Result.ok(fileUploadService.logoUpload(file));
    }

    @Operation(summary = "商品轮转图上传")
    @PostMapping("/product/sliderUpload")
    public Result sliderUpload(@RequestParam("file") MultipartFile file){
        return Result.ok(fileUploadService.sliderUpload(file));
    }

    @Operation(summary = "商品商品详细图上传")
    @PostMapping("/product/detailUpload")
    public Result detailUpload(@RequestParam("file") MultipartFile file){
        return Result.ok(fileUploadService.detailUpload(file));
    }

    @Operation(summary = "商品轮转图取消上传")
    @PostMapping("/product/sliderRemove")
    public Result sliderUpload(String fileName){
        fileUploadService.sliderRemove(fileName);
        return Result.ok();
    }
}
